<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>热表分厂转工排产查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'热表分厂转工排产查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="承制分厂:">
          <el-select v-model="queryInfo.tofactoryid" placeholder="请选择承制分厂" disabled>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="主制分厂:" prop="fromfactoryid">
          <el-select v-model="queryInfo.fromfactoryid" placeholder="请选择主制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="plannedfinishdate" label="计划完成时间:">
          <el-date-picker v-model="queryInfo.plannedfinishdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="完成状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择完成状态" clearable filterable>
            <el-option :key="'待完成'" :label="'待完成'" :value="'待完成'"></el-option>
            <el-option :key="'已完成'" :label="'已完成'" :value="'已完成'"></el-option>
          </el-select>
        </el-form-item>

        <div>
          <el-form-item prop='productname' label="零件图号:">
            <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
              style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
            </el-autocomplete>
          </el-form-item>
          <el-form-item prop='containername' label="流水卡号:">
            <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
              style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'"
              :debounce="500">
            </el-autocomplete>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handlerSearch">查询</el-button>
            <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
          </el-form-item>
        </div>
      </el-form>

      <!-- 汇总显示区域 -->
      <el-form class="compute-info-zone" :inline="true" :label-position="'left'">
        <el-form-item label="排产零件数:">
          <el-tag>{{computeData.productCount}}</el-tag>
        </el-form-item>

        <el-form-item label="排产工序数:">
          <el-tag>{{computeData.specCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期天数:">
          <el-tag type="danger">{{computeData.delaydaySum}}</el-tag>
        </el-form-item>

        <el-form-item label="超期工序数:">
          <el-tag type="warning">{{computeData.delaySpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="完工工序数:">
          <el-tag type="success">{{computeData.finishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="按时完工数:">
          <el-tag type="success">{{computeData.intimeFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期完成数:">
          <el-tag type="warning">{{computeData.delayFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="未完工序数:">
          <el-tag type="danger">{{computeData.notFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="完成率 = 完工工序数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="完成率:">
            <el-tag type="success">{{computeData.finishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="按时完成率 = 按时完工数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="按时完成率:">
            <el-tag type="success">{{computeData.intimeFinishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="超期完成率 = 超期完成数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="超期完成率:">
            <el-tag type="warning">{{computeData.delayFinishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="未完成率 = 未完工序数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="未完成率:">
            <el-tag type="danger">{{computeData.notFinishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="\n ">
              <i class="el-icon-info" slot="reference"></i>
              <p>按时送达率 = A ÷ B。</p>
              <p>A: 主制分厂、承制分厂都已排产，且主制分厂在“计划发出时间”之内已发出的工序数。</p>
              <p>B: 主制分厂、承制分厂都已排产的工序数。</p>
            </el-popover>
          </template>
          <el-form-item label="按时送达率:">
            <el-tag type="success">{{computeData.SendOutIntimeRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="\n ">
              <i class="el-icon-info" slot="reference"></i>
              <p>按时完成率 = A ÷ B。</p>
              <p>A: 主制分厂、承制分厂都已排产，主制分厂在“计划发出时间”内已发出，承制分厂在“计划完成时间”内完成的工序数。</p>
              <p>B: 主制分厂、承制分厂都已排产，主制分厂在“计划发出时间”内已发出的工序数。</p>
            </el-popover>
          </template>
          <el-form-item label="按时完成率:">
            <el-tag type="success">{{computeData.finishRateNew}}%</el-tag>
          </el-form-item>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="主制分厂" prop="fromfactory" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip></el-table-column>
        <el-table-column label="排产工序" prop="workflowstepname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="主制分厂排产时间" prop="stepplancreatedate" width="130" :formatter="splitDate">
        </el-table-column>
        <el-table-column label="承制分厂排产时间" prop="stepplanshipdate" width="130" :formatter="splitDate"></el-table-column>
        <el-table-column label="计划发出时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="实际发出时间" prop="senddate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="接收时间" prop="toacceptdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="计划完成时间" prop="plannedfinishdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="实际完成时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="主制分厂转入日期" prop="recivedate" width="130" :formatter="splitDate"></el-table-column>
        <el-table-column label="发出超期时间" prop="senddelaydays" width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.senddelaydays > 0" style="color:red;font-weight:bold;">
              <i class="el-icon-warning"></i> {{scope.row.senddelaydays}}天
            </div>
            <div v-else>
              {{scope.row.senddelaydays}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="完成超期时间" prop="finishdelaydays" width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.finishdelaydays > 0" style="color:red;font-weight:bold;">
              <i class="el-icon-warning"></i> {{scope.row.finishdelaydays}}天
            </div>
            <div v-else>
              {{scope.row.finishdelaydays}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="其他信息" width="80" type="expand">
          <template slot-scope="props">
            <el-descriptions title="其他信息" border :column="8" :contentStyle="{'height':'30px'}" style="padding:10px;">
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 承制分厂
                </template>
                {{props.row.tofactory}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 零件图号
                </template>
                {{props.row.productname}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 零件名称
                </template>
                {{props.row.productdescription}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 责任工区
                </template>
                {{props.row.fromworkcentername}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 当前工序
                </template>
                {{props.row.currentworkflowstepname}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 数量
                </template>
                {{props.row.qty}}
              </el-descriptions-item>
            </el-descriptions>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[15,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getFactoryInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          tofactoryid: '',//承制分厂
          fromfactoryid: '',//发出分厂
          plannedfinishdate: '',//热表计划完成时间
          productname: '',//零件图号
          containername: '',//流水卡号
          status: '',// 完成状态
          currentPage: 1,//当前页
          pageSize: 15//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        factoryList: [],//发出分厂
        dataList: [],
        computeData: {},
        // 表单验证
        rules: { plannedfinishdate: [{ required: true, message: '计划完成时间不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        handlerSearch() {
          this.getData();
          this.getCompute();
        },
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              if (!this.queryInfo.tofactoryid) {
                return this.$message.error('承制分厂不能为空');
              }
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/RBContainerStepPlan.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        // 查询汇总数据
        async getCompute() {
          const { data: { data, meta, total } } = await axios.post('../handler/report/RBContainerStepPlan.ashx?action=getCompute', {
            type: 'getCompute',
            ...this.queryInfo
          })
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.computeData = data[0];
        },
        //导出excel
        async getExportExcel() {
          const config = {
            url: '../handler/report/RBContainerStepPlan.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        const factoryinfo = await getFactoryInfo({ factorycode: '602', isMapping: '是' });
        this.queryInfo.tofactoryid = factoryinfo[0].factoryid;
        const monday = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD')
        const sunday = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD')
        this.queryInfo.plannedfinishdate = [monday, sunday]
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>